﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.IO;
using System.Text;
using SpaceNeedle.x6473.WindowsPhone.ViewModels;
using SpaceNeedle.x6473.WindowsPhone.Common;
using Windows.Networking.Connectivity;
using SpaceNeedle.SDK.WindowsPhone.Views;

namespace SpaceNeedle.x6473.WindowsPhone.Views
{
    public class SocialView : ViewBase<SocialViewModel> { }
    public partial class Social : SocialView
    {
        public Social()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string strItemIndex;

            if (NavigationContext.QueryString.TryGetValue("goto", out strItemIndex))
            {
                int index = Convert.ToInt32(strItemIndex);
                panorama.DefaultItem = panorama.Items[index];
            }

            base.OnNavigatedTo(e);
        }

        private void OnFacebookPostsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0)
            {
                return;
            }

            this.ViewModel.PostDetailsCommand.Execute(e.AddedItems[0]);
            this.facebookPostsListBox.SelectedIndex = -1;
        }

        private void OnTwitterPostsListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count == 0)
            {
                return;
            }

            this.ViewModel.TwitterDetailsCommand.Execute(e.AddedItems[0]);
            this.twitterPostsListBox.SelectedIndex = -1;
        }

        private void OnUploadsMenuItem_Click(object sender, EventArgs e)
        {
            this.ViewModel.UploadsCommand.Execute(null);
        }

        private void OnAboutMenuItem_Click(object sender, EventArgs e)
        {
            this.ViewModel.AboutCommand.Execute(null);
        }

        private void OnSignOutMenuItem_Click(object sender, EventArgs e)
        {
            this.ViewModel.SignOutCommand.Execute(null);
        }
    }
}